<template>
  <div class="page-hero" v-if="model">
    <!-- topbar -->
    <div class="topbar bg-black px-3 py-2 flex flex-ai-center text-white">
      <img src="../assets/images/logo.png" alt height="30" />
      <div class="px-2 flex-1">
        <router-link to="/" tag="span">王者荣耀</router-link>
        <span class="ml-2">攻略站</span>
      </div>
      <router-link to="/" tag="div">更多英雄&nbsp;&gt;</router-link>
    </div>
    <!-- banner -->
    <div class="top" :style="{'background-image':`url(${model.banner})`}">
      <div class="info text-white p-3 h-100 flex flex-column flex-jc-end">
        <div class="fs-sm">{{model.title}}</div>
        <h2 class="my-2">{{model.name}}</h2>
        <div class="fs-sm">{{model.tag}}</div>
        <div class="flex flex-jc-between pt-2">
          <div class="scores flex flex-ai-center" v-if="model.scores">
            <span>难度</span>
            <span class="badge bg-primary">{{model.scores.difficult}}</span>
            <span>技能</span>
            <span class="badge bg-blue">{{model.scores.skills}}</span>
            <span>攻击</span>
            <span class="badge bg-danger">{{model.scores.attack}}</span>
            <span>生存</span>
            <span class="badge bg-brown">{{model.scores.survive}}</span>
          </div>
          <router-link tag="span" to="#" class="text-grey fs-sm">皮肤 &gt;</router-link>
        </div>
      </div>
    </div>
    <!-- content -->
    <div class="px-3 bg-white border-bottom">
      <ul class="nav flex-jc-around text-grey-1 border-bottom py-2">
        <router-link to="/" tag="div" class="nav-item active">英雄初识</router-link>
        <router-link to="/" tag="div" class="nav-item">进阶攻略</router-link>
      </ul>
      <div class="panel py-3" v-if="model.skills">
        <ul class="plus-tab flex flex-jc-around">
          <li
            class="skill-item text-center"
            :class="{current:current ==index}"
            v-for="(item,index) in model.skills"
            :key="item._id"
            @click="current = index"
          >
            <img :src="item.icon" alt />
          </li>
        </ul>
        <ul class="plus-content">
          <li v-show="index==current" v-for="(item,index) in model.skills" :key="item._id">
            <div class="plus-box my-4">
              <strong class="fs-lg mr-3">{{item.name}}</strong>
              <span class="fs-sm">(冷却值:{{item.delay}} 消耗:{{item.cost}})</span>
            </div>
            <div>{{item.description}}</div>
          </li>
        </ul>
      </div>
    </div>
    <lite-card icon="menu" title="出装推荐">
      <ul class="fs-xl">
        <li class="mt-3">
          <div>顺风出装</div>
          <ul class="flex mt-2 pb-2 flex-jc-around border-bottom">
            <li class="item text-center" v-for="(item,index) in model.items1" :key="index">
              <img :src="item.icon" alt srcset />
              <div class="fs-sm">{{item.name}}</div>
            </li>
          </ul>
        </li>
        <li class="mt-3">
          <div>逆风出装</div>
          <ul class="flex mt-2 pb-2 flex-jc-around border-bottom">
            <li class="item text-center" v-for="(item,index) in model.items2" :key="index">
              <img :src="item.icon" alt srcset />
              <div class="fs-sm">{{item.name}}</div>
            </li>
          </ul>
        </li>
      </ul>
    </lite-card>
    <lite-card icon="menu" title="使用技巧">
      <div>{{model.usageTips}}</div>
    </lite-card>
    <lite-card icon="menu" title="对抗技巧">
      <div>{{model.battleTips}}</div>
    </lite-card>
    <lite-card icon="menu" title="团战思路">
      <div>{{model.teamTips}}</div>
    </lite-card>
  </div>
</template>

<script>
export default {
  props: {
    id: { required: true }
  },
  computed: {},
  data() {
    return {
      model: {
        skills: null,
        item1: null,
        item2: null
      },
      current: 0
    };
  },
  methods: {
    async fetch() {
      const res = await this.$http.get(`heroes/${this.id}`);
      this.model = res.data;
    }
  },
  created() {
    this.fetch();
  }
};
</script>

<style lang="scss">
@import "../assets/style/_variables.scss";

.topbar {
  position: sticky;
  top: 0;
  z-index: 999;
}

.page-hero {
  .top {
    height: 50vw;
    background: #fff no-repeat top center;
    background-size: auto 100%;
  }

  .info {
    background: linear-gradient(rgba(0, 0, 0, 0), rgba(0, 0, 0, 1));

    .scores {
      .badge {
        margin: 0 0.25rem;
        display: inline-block;
        width: 1rem;
        height: 1rem;
        line-height: 0.85rem;
        text-align: center;
        border-radius: 50%;
        font-size: 0.8rem;
        border: 1px solid rgba(255, 255, 255, 0.2);
      }
    }
  }
}

.skill-item > img {
  display: inline-block;
  width: 4.5rem;
}

.current > img {
  border: 0.2rem solid map-get($colors, "primary");
  border-radius: 50%;
}

.item > img {
  width: 3rem;
  border-radius: 50%;
}
</style>